package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.RoleClient;
import com.salt.admin.api.model.Role;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

/**
 * @Description
 * @Author salt
 * @Date 2021-04-08
 * @Version 1.0.1
 */
@Slf4j
@Component
public class RoleClientHystrix implements FallbackFactory<RoleClient> {

    @Override
    public RoleClient create(Throwable throwable) {
        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);
        return new RoleClient() {
            @Override
            public List<Role> findAllList(Role role) {
                log.info("--获取角色异常--");
                return null;
            }

            @Override
            public Role get(String id) {
                log.info("--根据ID获取角色异常，ID: " + id);
                return null;
            }

            @Override
            public List<Role> queryByIds(List<String> ids) {
                log.info("--根据ID的集合获取角色异常");
                return null;
            }

            @Override
            public Set<String> selectUserIds(Set<String> roleIds) {
                log.info("--根据ID的集合获取用户异常");
                return null;
            }
        };
    }
}
